/**
 * Created by thinkl on 2017/6/24.
 */
$(function () {
    var app_data = {
        address_list: [],
        address_default: 0,
    };
    var app = new Vue({
        el: '#add_list',
        data: app_data,
        methods: {
            address_mod: function (add_id) {
                location.href = '/static/address_mod/address_mod.html?id=' + add_id
            },
            address_delete: function (add_id) {
                $.post('/address/address_delete', {address_id: add_id}, function (data) {
                });
            },
            chose_address: function (add_id) {
                var order_id = getQueryString('order_id');
                $.post('/order/address_mod', {order_id: order_id, address_id: add_id}, function (data) {
                    var res = JSON.parse(data);
                    if (res.success) {
                        location.href = '/static/order_detail/order_detail.html?order_id=' + order_id
                    }
                });
            },
            chose_default: function (add_id) {
                $.post('/address/address_is_default', {address_id: add_id}, function (data) {
                    var res = JSON.parse(data);

                    $.post('/address/query_address', {}, function (data) {
                        var l = JSON.parse(data);
                        app_data.address_list = l.result;
                    });

                })
            }
        }
    });
    $.post('/address/query_address', {}, function (data) {
        var l = JSON.parse(data);
        app_data.address_list = l.result;
        $.each(app_data.address_list, function (index, item) {
            if (item.is_default) {
                app_data.address_default = item.id;
            }
        })
    });

});
function create_address() {
    var order_id = getQueryString('order_id');
    location.href = '/static/create_address/create_address.html?order_id=' + order_id
}
